<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息 - 图书借阅系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .sidebar {
            background-color: white;
            min-height: calc(100vh - 56px);
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .sidebar .nav-link {
            color: #495057;
            padding: 15px 20px;
            border-bottom: 1px solid #dee2e6;
        }
        .sidebar .nav-link:hover {
            background-color: #f8f9fa;
            color: #007bff;
        }
        .sidebar .nav-link.active {
            background-color: #007bff;
            color: white;
        }
        .content {
            padding: 20px;
        }
        .profile-card {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <i class="fas fa-book"></i> 图书借阅系统
            </a>
            <div class="navbar-nav ms-auto">
                <span class="navbar-text me-3">
                    欢迎, ${sessionScope.reader.name}
                </span>
                <a class="nav-link" href="/reader/logout">退出登录</a>
            </div>
        </div>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3">
                <div class="sidebar">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="/reader/dashboard">
                                <i class="fas fa-tachometer-alt me-2"></i>个人中心
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/reader/profile">
                                <i class="fas fa-user me-2"></i>个人信息
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/borrow/myRecords">
                                <i class="fas fa-book me-2"></i>借阅记录
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/book/list">
                                <i class="fas fa-search me-2"></i>图书搜索
                            </a>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- 主内容区 -->
            <div class="col-md-9">
                <div class="content">
                    <h2>个人信息</h2>
                    <hr>

                    <div class="row">
                        <div class="col-md-8">
                            <div class="profile-card">
                                <h4>基本信息</h4>
                                <hr>
                                
                                <c:if test="${not empty success}">
                                    <div class="alert alert-success">${success}</div>
                                </c:if>
                                
                                <c:if test="${not empty error}">
                                    <div class="alert alert-danger">${error}</div>
                                </c:if>
                                
                                <form action="/reader/profile/update" method="post">
                                    <div class="mb-3">
                                        <label for="username" class="form-label">用户名</label>
                                        <input type="text" class="form-control" id="username" value="${reader.username}" readonly>
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="name" class="form-label">姓名 <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control" id="name" name="name" value="${reader.name}" required>
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="email" class="form-label">邮箱 <span class="text-danger">*</span></label>
                                        <input type="email" class="form-control" id="email" name="email" value="${reader.email}" required>
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="phone" class="form-label">电话</label>
                                        <input type="tel" class="form-control" id="phone" name="phone" value="${reader.phone}">
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="address" class="form-label">地址</label>
                                        <textarea class="form-control" id="address" name="address" rows="3">${reader.address}</textarea>
                                    </div>
                                    
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-save"></i> 保存修改
                                    </button>
                                </form>
                                
                                <hr>
                                
                                <h5>修改密码</h5>
                                <form action="/reader/profile/changePassword" method="post">
                                    <div class="mb-3">
                                        <label for="currentPassword" class="form-label">当前密码</label>
                                        <input type="password" class="form-control" id="currentPassword" name="currentPassword" required>
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="newPassword" class="form-label">新密码</label>
                                        <input type="password" class="form-control" id="newPassword" name="newPassword" required>
                                    </div>
                                    
                                    <div class="mb-3">
                                        <label for="confirmPassword" class="form-label">确认新密码</label>
                                        <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
                                    </div>
                                    
                                    <button type="submit" class="btn btn-warning">
                                        <i class="fas fa-key"></i> 修改密码
                                    </button>
                                </form>
                            </div>
                        </div>
                        
                        <div class="col-md-4">
                            <div class="profile-card">
                                <h5>账户信息</h5>
                                <hr>
                                <p><strong>用户名:</strong> ${reader.username}</p>
                                <p><strong>最大借阅数:</strong> ${reader.maxBooks}</p>
                                <p><strong>注册时间:</strong> ${reader.createTime}</p>
                                <p><strong>当前借阅:</strong> ${currentBorrowCount}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/js/bootstrap.bundle.min.js"></script>
</body>
</html>